
<?php 
	$productID = $_GET['proID'];
	$productOptionAll = $productOption->show_product_option_by_product($productID);
	$productdetail = $product->show_product_by_id($productID);
?>
<?php 
	if(isset($_POST['update']))
	{	
		$productName = $_POST['productName'];
		$product->update($productID, $productName);
		foreach ($_POST['option'] as $option) 
		{		
			$productOption->update($productID, $option['title'], $option['position'],$option['optionID']);			
		}
		header("Location: index.php");
	}
?>
<p></p>
<p></p>
<div class="content-admin-edit">
	<div class="product-title">Edit Option</div>
	<div class="tbl"> 
		<form action="" method="Post">
        	<table border="0">
        		<tr>
	               <td class ="option-td">
						Product name: 
	               </td>
	               <td colspan="2" style="text-align: left;">
	                   <input class="txt-option" type="text" name="productName" size="30" value="<?php echo $productdetail['productName']?>"/>
	               </td>         	
           		</tr>
	        	<tr>
	               <td class ="option-td"></td>
	               <td style="background-color: #CCC;"> Title</td>
	               <td style="background-color: #CCC;">Position</td>      	
	           	</tr>
           
        	<?php 
        		$i=1;
        		foreach ($productOptionAll as $productOption)
        		{
        	?>
        		<tr>
	                <td class ="option-td">
						Option <?php echo $i?>
	                </td>
	                <td>
	                    <input class="txt-option" type="text" name="option[<?php echo $i; ?>][title]" size="30" value="<?php echo $productOption['title']?>"/>
	                </td>
	                <td>
	                    <input class="txt-option" type="text" name="option[<?php echo $i; ?>][position]" size="10" value="<?php echo $productOption['position']?>"/>
	                </td>
	                	<input class="txt-option" type="hidden" name="option[<?php echo $i; ?>][optionID]" size="10" value="<?php echo $productOption['optionID']?>"/>	               
           		</tr>
            <?php $i++;}?>
            <tr>
                <td style="text-align: center;" colspan="2" class="button-deactive">
                    <input type="submit" value="Update" name="update" class="button mws-button blue"/>
                </td>               
            </tr>
            <tr>
            	<td>
            		<a href="index.php" style="text-decoration:none">Return List</a>
            	</td>
            </tr>
        </table>
    </form>
   </div>
</div>
